public class Day4 {

    public static void main(String[] args) {

        System.out.println(isHappy(20));
        System.out.println(isHappy(19));
        System.out.println(isHappy(2));
        System.out.println(isHappy(4));

    }

    public static boolean isHappy(int n) {

        int origin = n;

        //n不是个位数 或者 n方大于10且n不重复
        while (n / 10 != 0 ) {

            int sum = 0;
            for (; n != 0; n /= 10) {
                int a = n % 10;
                sum += Math.pow(a, 2);
            }
            n = sum;

        }

        if (n != 1) {
            return false;
        }

        return true;

    }

}
